#include "../logger/Logger.h"
#include "../logger/EagerLogger.h"

#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"

TEST_CASE("test logger", "[test]") {
    std::cout << "## test logger" << std::endl;
    // 获取Logger单例实例
    Logger* logger1 = Logger::getInstance();
    Logger* logger2 = Logger::getInstance();
    std::cout <<  "- logger1 " <<logger1 << std::endl;
    REQUIRE(logger1 != nullptr);
    REQUIRE(logger2 != nullptr);
    
    // 验证是否是同一个实例
    if (logger1 == logger2) {
        std::cout << "- logger1 and logger2 are the same instance" << std::endl;
    }
    REQUIRE(logger1 == logger2);
    
    // 使用日志记录功能
    logger1->log("program start");
    logger1->logWarning("potential problem found");
    logger1->logError("error occurred");
    
    // 尝试创建新的实例（这是不允许的）
    // Logger logger3; // 这行代码会导致编译错误，因为构造函数是私有的
    
    // 程序结束前清理
    Logger::destroyInstance();

    
    logger1 = Logger::getInstance();
     
    std::cout <<  "- logger1 " <<logger1 << std::endl;
    
}

TEST_CASE("test eager logger", "[test]") {
    std::cout << std::endl;
    std::cout << "## test eager logger" << std::endl;
    // 获取EagerLogger单例实例
    EagerLogger* eagerLogger1 = EagerLogger::getInstance();
    EagerLogger* eagerLogger2 = EagerLogger::getInstance(); 
    REQUIRE(eagerLogger1 != nullptr);
    REQUIRE(eagerLogger2 != nullptr);

    // 验证是否是同一个实例
    if (eagerLogger1 == eagerLogger2) {
        std::cout << "- eagerLogger1 and eagerLogger2 are the same instance" << std::endl;
    }
    REQUIRE(eagerLogger1 == eagerLogger2);  

    // 使用日志记录功能
    eagerLogger1->log("program start");
    eagerLogger1->logWarning("potential problem found");
    eagerLogger1->logError("error occurred");
    
    // 尝试创建新的实例（这是不允许的）
    // EagerLogger eagerLogger3; // 这行代码会导致编译错误，因为构造函数是私有的
    
    // 程序结束前清理
    // EagerLogger::destroyInstance();

    
    eagerLogger1 = EagerLogger::getInstance();
    std::cout <<  "- eagerLogger1 " <<eagerLogger1 << std::endl; 
}
